/**
 * 
 */
package face.unisannio;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.List;

import com.github.mhendred.face4j.DefaultFaceClient;
import com.github.mhendred.face4j.FaceClient;
import com.github.mhendred.face4j.exception.FaceClientException;
import com.github.mhendred.face4j.exception.FaceServerException;
import com.github.mhendred.face4j.model.Face;
import com.github.mhendred.face4j.model.Photo;
import com.github.mhendred.face4j.model.SavedTag;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore.Images.Media;

/**
 * @author Fabio Melillo
 *
 */
public class SaveTagTask extends AsyncTask<Object, Integer, List<SavedTag>> {
	
	
	protected static final String API_KEY = "0889a9494b9775f3fadd8ef7179ab671";
	protected static final String API_SEC = "4f670ea4195306cbc88a940d5d1b72d2";
	protected static final String NAMESPACE = "fabio.melillo";
	private ProgressDialog dialog;
	private FaceClient faceClient;
	private List<SavedTag> savedTag;
	private String uid,label;
	private Face face;
	
//	protected void onPreExecute() {
//		dialog = ProgressDialog.show(activity,"","Sto riconoscendo i volti. Attendere prego...", true);
//	}

	public SaveTagTask(Face face, String uid, String label) {
		this.face=face;
		this.uid=uid;
		this.label=label;
	}

	/* (non-Javadoc)
	 * @see android.os.AsyncTask#doInBackground(Params[])
	 */
	@Override
	protected List<SavedTag> doInBackground(Object... object) {
			try {
				faceClient = new DefaultFaceClient(API_KEY, API_SEC);
				savedTag = faceClient.saveTags(face.getTID(), uid+"@"+NAMESPACE, label);
			} catch (FaceClientException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FaceServerException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return savedTag;
	}

	
	@Override
	protected void onPostExecute(List<SavedTag> saved) {
		// TODO Auto-generated method stub
		super.onPostExecute(saved);
	}
}
